﻿using OpenHtmlToPdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FieldTools.Util.Helper
{
    /// <summary>
    /// pdf帮助类，不好用，待扩展
    /// </summary>
    public class PDFHelper
    {
        public PDFHelper()
        {

        }
        /// <summary>
        /// 以默认配置保存html页面至指定路径
        /// </summary>
        /// <param name="htmlDoc"></param>
        /// <param name="savePathName"></param>
        public static void SavaPdfDefault(string htmlDoc, string savePathName)
        {
    //        const string html =
    //"<!DOCTYPE html>" +
    //"<html>" +
    //"<head><meta charset='UTF-8'><title>Title</title></head>" +
    //"<body>Body text...</body>" +
    //"</html>";

            var pdf = Pdf
                .From(htmlDoc)
                .Content();

            using FileStream file1 = new(savePathName, FileMode.CreateNew);
            file1.Write(pdf);
        }
    }
}
